import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.Stack;
/**
 * Write a description of class plantTurtle here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class plantTurtle extends Turtle
{
    /**
     * Act - do whatever the plantTurtle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    Stack<Integer> xStack = new Stack();
    Stack<Integer> yStack = new Stack();
    Stack<Integer> dirStack = new Stack();
    
    public plantTurtle(){
        penDown();
    }
    public void act() 
    {
        // Add your action code here.
    }    
    void pushOrientation(){
        xStack.push(getX());
        yStack.push(getY());
        dirStack.push(getDirection());
    }
    void popOrientation(){
        setLocation(xStack.pop(), yStack.pop());
        setDirection((Integer)dirStack.pop());
    }
    public void drawPlant(int n, double len){
        if(n == 0){
            move(len);
        } else {
            move(len);
            turn(-25);
            pushOrientation();
            pushOrientation();
            drawPlant(n-1, len * 0.5);
            popOrientation();
            turn(25);
            drawPlant(n-1, len * 0.5);
            popOrientation();
            turn(25);
            move(len);
            pushOrientation();
            turn(25);
            move(len);
            drawPlant(n-1, len * 0.5);
            popOrientation();
            turn(-25);
            drawPlant(n-1, len * 0.5);
        }
    }
}
